﻿using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Threading;
using WPFExcelReport;
namespace WPFExcelReport
{
    public partial class VABPOS
    {
        void DoJLTAV95Work()
        {
            if (IsRun)
            {
                return;
            }
            IsRun = true;
            string path = @"C:\IntexReport\Data\JLTAV95";
            string ITXDBVERSION = "JLT";
            JLTAV95(ITXDBVERSION, path);
        }

        public void JLTAV95(string ITXDBVERSION, string path)
        {
            try
            {
                while (true)
                {
                    DataSet SetJob = GetJob(path);
                    if (SetJob.Tables.Count == 0)
                    {
                        IsRun = false;
                        break;
                    }
                    CreateAB05(ITXDBVERSION, SetJob);
                    CreateAB55(ITXDBVERSION, SetJob);
                    CreateAB45(ITXDBVERSION, SetJob);
                    CreateAB50(ITXDBVERSION, SetJob);
                    DataTable tbMU = SetJob.Tables["ICC_ABAX"];
                    if (tbMU != null)
                    {
                        string filter = "ABAID>0";
                        DataRow[] rows = tbMU.Select(filter);
                        List<DataRow> list = new List<DataRow>();
                        if (rows.Length > 0)
                        {
                            foreach (DataRow row in rows)
                            {
                                if (row["ABAWAKZ"].ToString().Trim() == "G")
                                    continue;
                                DataRow dwABAX = INTEXDBC.Convert2ICC_ABAX(row, app.company, true);
                                dwABAX["ABAID"] = 0;
                                list.Add(dwABAX);
                            }
                        }
                        SaveAB(ITXDBVERSION, list);
                    }
                }
                EventDispatcher.Instance.RaiseStatus("转换完成", StatusEventType.StopProgress);
            }
            catch (Exception ex)
            {
                EventDispatcher.Instance.RaiseStatus("转换异常终止", StatusEventType.StopProgress);
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {
                IsRun = false;
            }
        }
     
    }
}